﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace TournamentOrganizerWPF
{
    static class LoadSave
    {
        public static void SaveTournament(Tournament tournament)
        {
            IFormatter formatter = new BinaryFormatter();
            Stream stream = new FileStream("SavedTournament.bin",
                                     FileMode.Create,
                                     FileAccess.Write, FileShare.None);
            formatter.Serialize(stream, tournament);
            stream.Close();

        }

        public static Tournament LoadTournament()
        {
            IFormatter formatter = new BinaryFormatter();
            try
            {
                Stream stream = new FileStream("SavedTournament.bin",
                                      FileMode.Open,
                                      FileAccess.Read,
                                      FileShare.Read);
                var tournament = (Tournament)formatter.Deserialize(stream);
                stream.Close();
                return tournament;
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
